import { reqGetSearchInfo } from "@/api"

const actions = {
    //当前这个函数在获取服务器数据的时候至少传递一个空对象
    async getSearchList({ commit }, params = {}) {
        const result = await reqGetSearchInfo(params)
        if (result.code == 200) {
            commit('GETSEARCHLIST', result.data)
        }
    },
}
const mutations = {
    GETSEARCHLIST(state, searchList) {
        state.searchList = searchList
    }
}
const state = {
    // 仓库初始状态
    searchList: {}
}
// 计算属性,在项目中为了简化数据而生
const getters = {
    goodsList(state) {
        //正常返回的是数组,如果没有网,这里的请求返回的是undefined,undefined是无法遍历的,这里至少保证返回的是空数组
        return state.searchList.goodsList || []
    },
    trademarkList(state) {
        return state.searchList.trademarkList || []
    },
    attrsList(state) {
        return state.searchList.attrsList || []
    },

}

export default {
    state, actions, mutations, getters
}